/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.bsc.mgwt.client.activity;

import org.bsc.mgwt.client.ClientFactory;
import org.bsc.mgwt.client.mvp.MVPAbstractActivity;
import org.bsc.mgwt.client.place.Tab2Place;
import org.bsc.mgwt.client.ui.MVPExplorerView;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.googlecode.mgwt.mvp.client.Animation;
import com.googlecode.mgwt.mvp.client.AnimationMapper;

/**
 * Activities are started and stopped by an ActivityManager associated with a container Widget.
 */
public class MVPExplorerActivity extends MVPAbstractActivity implements MVPExplorerView.Presenter {

	/**
	 * 
	 */
	@Override
	public AnimationMapper getAnimationMapper() {
		return new  AnimationMapper() {

			@Override
			public Animation getAnimation(Place oldPlace, Place newPlace) {
				return Animation.SLIDE_REVERSE;
			}

		};
	}

	/**
	 * 
	 */
	@Override
	public ActivityMapper getActivityMapper() {
		return new ActivityMapper() {

			@Override
			public Activity getActivity(Place place) {
				
				if( place instanceof Tab2Place) {
					return new Tab2Activity((Tab2Place)place, clientFactory);
				}
				return null;
			}
		};
	}

	/**
	 * 
	 * @param clientFactory
	 */
	public MVPExplorerActivity(ClientFactory clientFactory) {
		super( clientFactory, clientFactory.getMVPExplorerView() );

		//goTo( Place.NOWHERE, 500);
		goTo(new Tab2Place("1ST ONE"), 200);
				
	}

	/**
	 * 
	 */
	@Override
	public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
		
		MVPExplorerView view = clientFactory.getMVPExplorerView();
		view.setPresenter(this);

		containerWidget.setWidget(view.asWidget());
	
	}

	/**
	 * 
	 */
	@Override
	public String mayStop() {
		return null; //"Please hold on. This activity is stopping.";
	}

}
